#include <stdio.h>
#include <string.h>

bool validate(int k, char* buff, int m)
{ 
    int num = 2 * k;

    int cnt = 0;
    int idx = 0;
    int bad_cnt = 0;

    while(true)
    {
        cnt = 0;
        int left_len = num - bad_cnt;
        int mod = m % left_len;
        mod = mod == 0 ? left_len : mod; 
        while(true)
        {
            if(idx >= 2 * k)
                idx = 0;

            if(buff[idx])
            {
                idx ++;
                continue;
            }
            cnt ++;
            if(cnt == mod)
                break;

            idx ++;
        }

        if(idx < k)
            return false;

        bad_cnt ++;
        buff[idx] = 1;
        if(bad_cnt == k)
            break;

    }

    return true;
}


int main(void)
{
    int k;
    char buff[28];
    int solution[14];

    memset(solution, 0, 14 * sizeof(int));

    while(true)
    {
        scanf("%d", &k);
        if(!k)
            break;

        if(solution[k])
        {
            printf("%d\n", solution[k]);
            continue;
        }

        int i = 0;
        int num = 2 * k;
        int min_mod = k + k / 2 + 1;
        for(i = k + 1; ; i ++)
        {
            if((i - 1) % num < k)
                i += k - (i - 1) % num;

            memset(buff, 0, 2 * k);
            bool b = validate(k, buff, i);            
            if(b)
                break;
        }
        solution[k] = i;

        printf("%d\n", i);
    }

    return 0;
}
